<div align="center" class="home_progress">
<?php
		

	
	/*$selectStatistics = $db->select()->from('translation',array(
										'nbrTrans' => 'sum( CASE WHEN `id_status` BETWEEN 1 AND 2 THEN 1 ELSE 0 END )', 
										'Total' =>'sum(	CASE WHEN `id_status` BETWEEN 0 AND 2 THEN 1 ELSE 0 END )') 
													)
								->join('keys','keys.id_key=translation.id_key','id_projet')
								->join('projets','projets.id_projet=keys.id_projet','name')
								->join('languages','languages.id_lang=translation.id_lang',array('short_name','flag'))
								->where('languages.status=1')
								->group(array('translation.id_lang','projets.id_projet'))
								->order(array('projets.id_projet', 'languages.id_lang'));*/
								
	$selectStatistics = '
SELECT
    count(*) as nbrTrans,
    k.`id_projet`,
    t.`id_lang`
  FROM translation t
    JOIN `keys` as k ON t.`id_key`=k.`id_key`
  WHERE t.`id_status` = 1
    OR t.`id_status` = 2
  GROUP BY k.`id_projet`, t.`id_lang`
  ORDER BY  k.`id_projet`, t.`id_lang` ASC
';
	$resultStatistics = $db->fetchAll($selectStatistics);
	
	function getIsExistsStats($id_projet, $id_lang){
		global $resultStatistics;
		foreach($resultStatistics as $stat)
			if($stat->id_projet==$id_projet && $stat->id_lang==$id_lang) return $stat;
		
		return false;		
	}
	
	$array_stats=array();
	foreach($resultProjects as $projet){		
		foreach($resultLangues as $langue){
			$item=getIsExistsStats($projet->id_projet, $langue->id_lang);
			if($item!==false){
				$item->Total=$projet->Total;
				$item->flag=$langue->flag;
				$item->short_name=$langue->short_name;
				$item->name=$projet->name;
				$array_stats[]=$item;
			}else{
				$item=new stdClass;		
				$item->id_projet=$projet->id_projet;
				$item->id_lang=$langue->id_lang;
				$item->nbrTrans=0;
				$item->Total=$projet->Total;
				$item->flag=$langue->flag;
				$item->short_name=$langue->short_name;
				$item->name=$projet->name;
				$array_stats[]=$item;
			}				
		}
	}
	$resultStatistics=$array_stats;
?>
	<table align="center">
	  <tr>
<?php 
	$id_projet=0;
	$j=0;
	foreach($resultStatistics as $stat){
			
		if($id_projet != $stat->id_projet && $id_projet!=0){
			$j++;			
			if($j%2==0){
			  	echo '</table></td><td width="0"></td></tr><tr><td colspan="3" class="sep_progress">&nbsp;</td></tr><tr>';
			}else{
				echo '</table></td><td width="100"></td>';
			}
		}
		if($id_projet != $stat->id_projet){ 		
		?>
		<td>
			<table align="center">
			 <tr>
			 	<td>
					<table width="100%"><tr><td class="name_project" valign="top"><?php echo $stat->name?>&nbsp;</td><td align="left" class="complete_at">Complete at:&nbsp;</td></tr></table>
			 	</td>
			 </tr>
<?php  } ?>			
			 <tr>
			 	<td align="left">
<?php 			
		$html='<table id="progressBar" background="/babili/img/bg_progress.jpg" cellspacing="0" cellpadding="0" border="0" width="360" ><tr>'."\n";
		
		$pourcent=ceil(($stat->nbrTrans/$stat->Total)*100);
		$width=ceil(270*$pourcent/100);
		$width_right=270-$width;
		
		if($stat->Total==$stat->nbrTrans){
			$class_progress="green"; $pourcent=100; 
		}else{
			$class_progress="blue";
		}
		
		$html .="<td class='".$class_progress."left' nowrap='nowrap' width='3'></td>\n";
		$html .="<td class='".$class_progress."' nowrap='nowrap' width='".$width."' height='16'></td>\n";
		$html .="<td nowrap='nowrap' height='16' class='progress_end_".$class_progress."' width='3'>&nbsp;</td>\n";
		$html .='<td class="progress_right"  nowrap="nowrap" width="'.$width_right.'"></td>';
		$html .='<td nowrap="nowrap" class="flag" valign="middle" width="16"><img src="'.$stat->flag.'" /></td>';
		$html .='<td class="pourcentage" valign="middle" align="left" width="30">'.$pourcent.'% '.$stat->nbrTrans.'</td>';
		$html .='<td class="pourcentage" valign="middle" align="left" width="16">'.$stat->short_name.'</td>';
        $html .='</tr></table>';
		echo $html; 		 
?>
				</td>
			</tr>
			
<?php  if($id_projet != $stat->id_projet){
	   		$id_projet = $stat->id_projet; 
	   }	  
	 
	}//End foreach
?>
  	  </table>
	 </td>
    </tr>
  </table>
  <p>&nbsp;</p>
</div>